<template>
	<view class="app-container">
		<view class="title">
			账号注册
		</view>
		<view class="form">
			<view class="item">
				<input v-model="form.username" type="text"  placeholder="注册手机"/>
			</view>
			<view class="item">
				<input v-model="form.nickname" type="text" placeholder="注册昵称"/>
			</view>
			<view class="item">
				<input v-model="form.password" type="password" placeholder="注册密码"/>
			</view>
		</view>
		<view class="btn">
			<button type="primary" @click="handleRegister">注 册</button>
		</view>
	</view>
</template>

<script>
	import {setToken} from '../../utils/auth.js'
	export default {
		data() {
			return {
				form:{
					username:'',
					password:'',
					nickname:''
				}
			}
		},
		methods: {
			handleRegister() {
				let username = this.form.username.trim()
				let password = this.form.password.trim()
				let nickname = this.form.nickname.trim()
				if(!username || !nickname || !password){
					return uni.showToast({
						icon:'none',
						title:'请填写完整'
					})
				}
				const reg = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/
				
				if(!reg.test(username)){
					return uni.showToast({
						icon:'none',
						title:'手机格式错误'
					})
				}
				
				this.$http('/api/user/register',"POST",this.form).then(res =>{
					uni.showToast({
						title:'注册成功'
					})
					setTimeout(() => {uni.reLaunch({
						url:'/pages/login/login'
					})},500)
				})
				
			},
			goPage(url) {
				uni.navigateTo({
					url:`/pages/login/${url}`
				})
			}
		}
	}
</script>

<style>
	.title{
		font-weight: bold;
		font-size: 24px;
		color: #666;
		padding: 10px 20px;
	}

	.item{
		display: flex;
		border-bottom: 2px solid #eee;
		margin: 10px 20px;
		padding: 10px;
	}
	.btn{
		padding: 10px 20px;
	}
	.btn-text{
		display: flex;
		justify-content: center;
	}
	.btn-text view{
		padding: 10px;
		color: #007aff;
	}
</style>
